/**
 *  @brief Brief description
 *  @athor victor.chen
 *  @corp  www.aiinone.cn
 */
 
#include "mcurpc.h"

bool RpcLaunchApp(uint8_t uApp, uint8_t uPage)
{
		uint8_t buf[ERPC_DATA_MIN_OFF] = {0};
		buf[0] = ERPC_FUNC_LAUNCHAPP;
		buf[1] = uApp;
		buf[2] = uPage;
		buf[3] = 0;
		printf("RpcLaunchApp,uApp:%d page:%d\n\r",uApp, uPage);
		return TF_SendSimple(gpMcuTf, EMCUCOM_TYPE_RPC, (const uint8_t *)buf, sizeof(buf));
}

bool RpcSetText(uint8_t uApp, uint8_t uPage, uint8_t uCtrl, uint8_t *pText, uint8_t len)
{
		uint8_t buf[MAX_RPCMESSAGE_LEN] = {0};
		uint8_t index =0;
		
		buf[0] = ERPC_FUNC_SETTEXT;
		buf[1] = uApp;
		buf[2] = uPage;
		buf[3] = uCtrl;
		
		len = len > MAX_RPCPARAMTER_LEN ? MAX_RPCPARAMTER_LEN:len;
		for(index = 0; index < len; ++index){
			buf[ERPC_DATA_MIN_OFF + index] = pText[index];
		}
		
		printf("RpcSetText,uApp:%d page:%d\n\r",uApp, uPage);
		return TF_SendSimple(gpMcuTf, EMCUCOM_TYPE_RPC, (const uint8_t *)buf, len + ERPC_DATA_MIN_OFF);
}

bool RpcSetBgImage(uint8_t uApp, uint8_t uPage, uint8_t uCtrl, uint8_t uH, uint8_t uL)
{
		uint8_t buf[ERPC_DATA_MIN_OFF + 2] = {0};
		uint8_t index =0;
		
		buf[0] = ERPC_FUNC_SETBGIMAGE;
		buf[1] = uApp;
		buf[2] = uPage;
		buf[3] = uCtrl;
		buf[4] = uH;
		buf[5] = uL;
	
		printf("RpcSetBgImage,uApp:%d page:%d\n\r",uApp, uPage);
		return TF_SendSimple(gpMcuTf, EMCUCOM_TYPE_RPC, (const uint8_t *)buf, 2 + ERPC_DATA_MIN_OFF);	
}

bool RpcSetBgColor(uint8_t uApp, uint8_t uPage, uint8_t uCtrl, uint8_t r, uint8_t g, uint8_t b, uint8_t a)
{
		uint8_t buf[ERPC_DATA_MIN_OFF + 4] = {0};
		uint8_t index =0;
		
		buf[0] = ERPC_FUNC_SETBGCOLOR;
		buf[1] = uApp;
		buf[2] = uPage;
		buf[3] = uCtrl;
		buf[4] = r;
		buf[5] = g;
		buf[6] = b;
		buf[7] = a;
		
		printf("RpcSetBgColor,uApp:%d page:%d\n\r",uApp, uPage);
		return TF_SendSimple(gpMcuTf, EMCUCOM_TYPE_RPC, (const uint8_t *)buf, 4 + ERPC_DATA_MIN_OFF);	
}

bool RpcSetCtrlAtt(uint8_t uApp, uint8_t uPage, uint8_t uCtrl, uint8_t uAtt)
{
		uint8_t buf[ERPC_DATA_MIN_OFF + 1] = {0};
		uint8_t index =0;
		
		buf[0] = ERPC_FUNC_SETCTRLTATT;
		buf[1] = uApp;
		buf[2] = uPage;
		buf[3] = uCtrl;
		buf[4] = uAtt;
		
		printf("RpcSetCtrlAtt,uApp:%d page:%d\n\r",uApp, uPage);
		return TF_SendSimple(gpMcuTf, EMCUCOM_TYPE_RPC, (const uint8_t *)buf, 1 + ERPC_DATA_MIN_OFF);	
}

bool RpcSetColor(uint8_t uApp, uint8_t uPage, uint8_t uCtrl, uint8_t r, uint8_t g, uint8_t b, uint8_t a)
{
		uint8_t buf[ERPC_DATA_MIN_OFF + 4] = {0};
		uint8_t index =0;
		
		buf[0] = ERPC_FUNC_SETCOLOR;
		buf[1] = uApp;
		buf[2] = uPage;
		buf[3] = uCtrl;
		buf[4] = r;
		buf[5] = g;
		buf[6] = b;
		buf[7] = a;
		
		printf("RpcSetBgImage,uApp:%d page:%d\n\r",uApp, uPage);
		return TF_SendSimple(gpMcuTf, EMCUCOM_TYPE_RPC, (const uint8_t *)buf, 4 + ERPC_DATA_MIN_OFF);	
}

bool RpcSetTextAtt(uint8_t uApp, uint8_t uPage, uint8_t uCtrl, uint8_t uAtt)
{
		uint8_t buf[ERPC_DATA_MIN_OFF + 1] = {0};
		uint8_t index =0;
		
		buf[0] = ERPC_FUNC_SETTEXTATT;
		buf[1] = uApp;
		buf[2] = uPage;
		buf[3] = uCtrl;
		buf[4] = uAtt;
		
		printf("RpcSetCtrlAtt,uApp:%d page:%d\n\r",uApp, uPage);
		return TF_SendSimple(gpMcuTf, EMCUCOM_TYPE_RPC, (const uint8_t *)buf, 1 + ERPC_DATA_MIN_OFF);	
}